using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QLNhaSach.BUS;
using QLNhaSach.BUS.DTO;

namespace QLNhaSach.GUI.NhanVienQuanLy
{
    public partial class KiemTraHoaDonNhapVaXuatSach : Form
    {
        DataTable dt = new DataTable();

        public KiemTraHoaDonNhapVaXuatSach()
        {
            InitializeComponent();
        }

        private void ClearForm()
        {
            txtMaHD.Clear();
            txtNguoiLap.Clear();
            rbNhap.Select();
            dtpNgayLap.Value.ToLocalTime();
            txtMaHD.Focus();
        }

        private void ShowListView(DataTable dt)
        {
            lvDSHoaDon.Items.Clear();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];
                ListViewItem item = new ListViewItem();
                item.Text = dr["Loai"].ToString();
                item.SubItems.Add(dr["NgayCap"].ToString());
                item.SubItems.Add(dr["HoTen"].ToString());
                item.SubItems.Add(dr["TenKH"].ToString());
                item.SubItems.Add(dr["TongTien"].ToString());
                lvDSHoaDon.Items.Add(item);
            }
        }

        private void KiemTraHoaDonNhapVaXuatSach_Load(object sender, EventArgs e)
        {
            dt = NhanVienQuanLyBUS.DSHD();
            ShowListView(dt);
        }

        private void lvDSHoaDon_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = lvDSHoaDon.FocusedItem.Index;
            if (index != -1)
            {
                DataRow dr = dt.Rows[index];
               
                txtMaHD.Text = dr["MaHD"].ToString();
                txtNguoiLap.Text = dr["HoTen"].ToString();
                dtpNgayLap.Text = dr["NgayCap"].ToString();
                if (Convert.ToInt16(dr["Loai"].ToString()) == 1)
                    rbNhap.Checked = true;
                else
                    rbXuat.Checked = true;
            }
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            ClearForm();
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            dt = NhanVienQuanLyBUS.DSHD();
            ShowListView(dt);
        }
    }
}